package com.yunxi.controller.sto;

import com.yunxi.sto.pojo.StoWorkDayVO;
import com.yunxi.sto.service.StoWorkDayDubboService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yunxi.core.web.ResponseUtil;
import java.util.*;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.LoginInfo;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 人员排班表 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-08-15
 */
@RestController
@RequestMapping("/admin/stoWorkDay")
@Api(tags = "sto:workDay", description = "人员排班表接口")
public class StoWorkDayController {
    private static final Logger logger = LoggerFactory.getLogger(StoWorkDayController.class);

    @Autowired
    StoWorkDayDubboService stoWorkDayDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(StoWorkDayVO stoWorkDayVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        stoWorkDayVO.setPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(stoWorkDayDubboService.findPageByVO(stoWorkDayVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(StoWorkDayVO stoWorkDayVO) throws Exception {
        return ResponseUtil.ok(stoWorkDayDubboService.listByVo(stoWorkDayVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "workDayId", value = "主键ID", required = true, dataType = "String")
    public ApiResult load(String workDayId) throws Exception {
        return ResponseUtil.ok(stoWorkDayDubboService.getById(workDayId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody StoWorkDayVO stoWorkDayVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoWorkDayVO.setPartnerCode(loginInfo.getPartnerCode());
        stoWorkDayDubboService.saveOrUpdate(stoWorkDayVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<StoWorkDayVO> stoWorkDayVOList) throws Exception {
        stoWorkDayDubboService.removeByListVo(stoWorkDayVOList);
        return ResponseUtil.ok("success");
    }

}
